package com.baidu.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baidu.entity.PageResult;
import com.baidu.entity.QueryPageBean;
import com.baidu.entity.Result;
import com.baidu.pojo.Evaluation;
import com.baidu.service.EvaluationService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/evaluation")
public class EvaluationController {

	@Reference
	private EvaluationService evaluationService;

	//查
	@RequestMapping("/pageQuery")
	public PageResult pageQuery(@RequestBody QueryPageBean queryPageBean){
		PageResult pageResult = evaluationService.pageQuery(queryPageBean);
		return pageResult;

	}


	//删
	@DeleteMapping("/delete/{id}")
	public Result delete(@PathVariable Integer id){

		try {
			evaluationService.delete(id);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			return  new Result(false,"删除失败");
		}


	}

	//添加
	@RequestMapping("/add")
	public Result add(@RequestBody Evaluation evaluation) {//传递过来的是json、对象

		try {
			evaluationService.add(evaluation);
			return 	new Result(true, "添加成功");

		} catch (Exception e) {
			return 	new Result(false, "添加失败");
		}


	}

	//	回显单个
	@GetMapping("/findById/{id}")
	public Result findById(@PathVariable Integer id){
		try {
			Evaluation evaluation= evaluationService.findById(id);
			return new Result(true,"",evaluation);
		} catch (Exception e) {
			return new Result(false,"");
		}
	}

	//编辑
	@PostMapping("/edit")
	public Result editCheckItem(@RequestBody Evaluation evaluation){

		try {
			evaluationService.edit(evaluation);
			return new Result(true, "编辑成功");
		} catch (Exception e) {
			return new Result(false,"编辑失败");
		}


	}




}
